<template>
  <div class="login-container" style="flex-wrap: wrap !important;flex-direction: column; justify-content: center;"
    @keyup.enter.native="handleLogin" :style='"background: url(" + currentRow.bgImgUrl + "); "'>
    <top-color v-show="false"></top-color>
    <div class="login-weaper animated bounceInDown">
      <div class="login-left" :style='"background: url(" + currentRow.loginBgUrl + "); background-repeat: no-repeat;"'>
        <div class="login-time">
          {{ time }}
        </div>


      </div>
      <div class="login-border">
        <div class="login-main">
          <h4 class="login-title">
            {{ currentRow.tenantName }}
            <top-lang></top-lang>
          </h4>
          <userLogin v-if="activeName === 'user'"></userLogin>
          <codeLogin v-else-if="activeName === 'code'"></codeLogin>
          <thirdLogin v-else-if="activeName === 'third'"></thirdLogin>
          <!-- <div class="login-menu">
            <a href="#"
               @click.stop="activeName='user'">{{ $t('login.userLogin') }}</a>
            <a href="#"
               @click.stop="activeName='code'">{{ $t('login.phoneLogin') }}</a>
            <a href="#"
               @click.stop="activeName='third'">{{ $t('login.thirdLogin') }}</a>
          </div> -->
        </div>
      </div>
    </div>
    <div style="flex-wrap: wrap; justify-content: flex-end;position: absolute; bottom:10px; font-size:14px;">
      Copyright ©2021-2024独领云科技 备案号：<a href="https://beian.miit.gov.cn/" target="_blank">蜀ICP备2020XXXX号-1</a>
    </div>
  </div>
</template>
<script>
import userLogin from './userlogin';
import codeLogin from './codelogin';
import thirdLogin from './thirdlogin';
import { mapGetters } from 'vuex';
import { dateFormat } from '@/util/date';
import { validatenull } from '@/util/validate';
import topLang from '@/page/index/top/top-lang';
import topColor from '@/page/index/top/top-color';
import { exportSysTenantInfoExcel, generateLicense, saveOrUpdateSysTenantInfo, saveOrUpdateSysTenantInfoList, saveSysTenantInfo, saveSysTenantInfoList, deleteSysTenantInfo, querySysTenantInfo, querySysTenantInfoListPage, updateSysTenantInfo, deleteSysTenantInfoList } from '@/api/system/sysTenantInfoApi';
import { reqCommonMsg } from '@/util/reqCommonMsg';
export default {
  name: 'login',
  components: {
    userLogin,
    codeLogin,
    thirdLogin,
    topLang,
    topColor
  },
  data() {
    return {
      time: '',
      activeName: 'user',
      tenantId: '',
      data: [],
      currentRow: {},
      // 请求参数区
      page: {
        pageSize: 10,
        currentPage: 1,
        total: 0
      },
      reqParams: {
        singleBody: {},
        listBody: [{}],
        sqlCondition: [],
        orderRule: {},
        currentPage: 1,
        pageSize: 10
      },
      commonData: null,
      conditions: [],
      orderRules: [],
      singleBody: {}
    };
  },
  watch: {
    // $route() {
    //   const params = this.$route.query;
    //   this.socialForm.state = params.state;
    //   this.socialForm.code = params.code;
    //   if (!validatenull(this.socialForm.state)) {
    //     const loading = this.$loading({
    //       lock: true,
    //       text: `${
    //         this.socialForm.state === 'WX' ? '微信' : 'QQ'
    //       }登录中,请稍后。。。`,
    //       spinner: 'el-icon-loading'
    //     });
    //     setTimeout(() => {
    //       loading.close();
    //     }, 2000);
    //   }
    // },
    '$route'(to, from) {
      location.reload();
    },
  },
  created() {
    let urlParam = this.$toolUtil.UrlSearch();
    if (urlParam.tenantId) {
      this.tenantId = urlParam.tenantId;
    }
    else {
      this.tenantId = this.website.defaultTenantId;
    }
    this.onLoad();
    this.getTime();
    setInterval(() => {
      this.getTime();
    }, 1000);
  },
  mounted() {
    //this.reload();
  },
  computed: {
    ...mapGetters(['website', 'userInfo'])
  },
  props: [],
  methods: {
    getTime() {
      this.time = dateFormat(new Date());
    },
    /**
     * 加载列表数据
     */
    onLoad() {
      this.loading = true;
      this.reqParams = {
        singleBody: {
          tenantId: this.tenantId
        },
        listBody: [{}],
        sqlCondition: this.conditions,
        orderRule: this.orderRules,
        currentPage: 1,
        pageSize: 10
      }
      this.commonData = reqCommonMsg(this.reqParams)
      querySysTenantInfoListPage(this.commonData).then(res => {
        const data = res.data.body;
        this.data = data.listBody;
        if (this.data.length > 0) {
          this.currentRow = this.data[0];
        }
        else {
          this.$message({
            customClass: 'zZindex',
            type: 'warning',
            message: '获取租户信息失败!'
          });
        }
        //动态更改浏览器ico
        var link = document.querySelector('link[rel*=\'icon\']') || document.createElement('link');
        link.type = 'image/x-icon';
        link.rel = 'shortcut icon';
        link.href = this.currentRow.logoUrl;
        document.getElementsByTagName('head')[0].appendChild(link);
        document.title = this.currentRow.tenantName || this.website.title;
        localStorage.setItem('companyName', this.currentRow.tenantName);
        localStorage.setItem('logoUrl', this.currentRow.logoUrl);
        localStorage.setItem('bigLogoUrl', this.currentRow.bigLogoUrl);

      }, error => {
        this.loading = false;
      });
    },
  }
};
</script>

<style lang="scss">
@import "@/styles/login.scss";
</style>